﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.t401Menu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void t401_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            t401Mgr mgr = new t401Mgr();
            e.Total = int.Parse(mgr.GetRecordCount_t401(e.Parameters[t401_Filter.ParamPrefix]));
            IList<t401> list = mgr.FindAllByPage_t401(e.Start.ToString(), e.Limit.ToString(), e.Parameters[t401_Filter.ParamPrefix]);
            t401_MainStore.DataSource = list;
            t401_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            t401Mgr mgr = new t401Mgr();
            RowSelectionModel sm = t401_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                t401 _t401 = new t401();
                _t401.t401_00 = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_t401(_t401))
                {
                    log.Debug("t401中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            t401_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            t401Mgr mgr = new t401Mgr();
            t401 _t401 = new t401();
            if (Hid.Text.Length > 0)
                _t401 = mgr.FindById_t401(int.Parse(Hid.Text));
            
			_t401.t401_70 = Txtt401_70.Text.Trim();
			_t401.t401_01 = Txtt401_01.Text.Trim();
			_t401.t401_02 = Txtt401_02.Text.Trim();
			_t401.t401_03 = Txtt401_03.Text.Trim();
			_t401.t401_04 = Txtt401_04.Text.Trim();
			_t401.t401_05 = Txtt401_05.Text.Trim();
			_t401.t401_06 = Txtt401_06.Text.Trim();
			_t401.t401_07 = Txtt401_07.Text.Trim();
			_t401.t401_08 = Txtt401_08.Text.Trim();
			_t401.t401_09 = Txtt401_09.Text.Trim();
			_t401.t401_10 = Txtt401_10.Text.Trim();
			_t401.t401_11 = Txtt401_11.Text.Trim();
			_t401.t401_12 = Txtt401_12.Text.Trim();
			_t401.t401_13 = Txtt401_13.Text.Trim();
			_t401.t401_14 = Txtt401_14.Text.Trim();
			_t401.t401_15 = Txtt401_15.Text.Trim();
			_t401.t401_16 = Txtt401_16.Text.Trim();
			_t401.t401_17 = Txtt401_17.Text.Trim();
			_t401.t401_18 = Txtt401_18.Text.Trim();
			_t401.t401_19 = Txtt401_19.Text.Trim();
			_t401.t401_20 = Txtt401_20.Text.Trim();
			_t401.t401_21 = Txtt401_21.Text.Trim();
			_t401.t401_71 = Txtt401_71.Text.Trim();
			_t401.t401_22 = Txtt401_22.Text.Trim();
			_t401.t401_23 = Txtt401_23.Text.Trim();
			_t401.t401_24 = Txtt401_24.Text.Trim();
			_t401.t401_25 = Txtt401_25.Text.Trim();
			_t401.t401_26 = Txtt401_26.Text.Trim();
			_t401.t401_27 = Txtt401_27.Text.Trim();
			_t401.t401_72 = Txtt401_72.Text.Trim();
			_t401.t401_28 = Txtt401_28.Text.Trim();
			_t401.t401_29 = Txtt401_29.Text.Trim();
			_t401.t401_30 = Txtt401_30.Text.Trim();
			_t401.t401_31 = Txtt401_31.Text.Trim();
			_t401.t401_32 = Txtt401_32.Text.Trim();
			_t401.t401_33 = Txtt401_33.Text.Trim();
			_t401.t401_73 = Txtt401_73.Text.Trim();
			_t401.t401_34 = Txtt401_34.Text.Trim();
			_t401.t401_35 = Txtt401_35.Text.Trim();
			_t401.t401_36 = Txtt401_36.Text.Trim();
			_t401.t401_37 = Txtt401_37.Text.Trim();
			_t401.t401_38 = Txtt401_38.Text.Trim();
			_t401.t401_39 = Txtt401_39.Text.Trim();
			_t401.t401_74 = Txtt401_74.Text.Trim();
			_t401.t401_40 = Txtt401_40.Text.Trim();
			_t401.t401_41 = Txtt401_41.Text.Trim();
			_t401.t401_42 = Txtt401_42.Text.Trim();
			_t401.t401_43 = Txtt401_43.Text.Trim();
			_t401.t401_44 = Txtt401_44.Text.Trim();
			_t401.t401_45 = Txtt401_45.Text.Trim();
			_t401.t401_46 = Txtt401_46.Text.Trim();
			_t401.t401_75 = Txtt401_75.Text.Trim();
			_t401.t401_47 = Txtt401_47.Text.Trim();
			_t401.t401_48 = Txtt401_48.Text.Trim();
			_t401.t401_49 = Txtt401_49.Text.Trim();
			_t401.t401_50 = Txtt401_50.Text.Trim();
			_t401.t401_51 = Txtt401_51.Text.Trim();
			_t401.t401_52 = Txtt401_52.Text.Trim();
			_t401.t401_53 = Txtt401_53.Text.Trim();
			_t401.t401_76 = Txtt401_76.Text.Trim();
			_t401.t401_77 = Txtt401_77.Text.Trim();
			_t401.t401_78 = Txtt401_78.Text.Trim();
			_t401.t401_79 = Txtt401_79.Text.Trim();
			_t401.t401_80 = Txtt401_80.Text.Trim();
			_t401.t401_81 = Txtt401_81.Text.Trim();
			_t401.t401_82 = Txtt401_82.Text.Trim();
			_t401.t401_83 = Txtt401_83.Text.Trim();
			_t401.t401_84 = Txtt401_84.Text.Trim();
			_t401.t401_85 = Txtt401_85.Text.Trim();
			_t401.t401_86 = Txtt401_86.Text.Trim();
			_t401.t401_87 = Txtt401_87.Text.Trim();
			_t401.t401_88 = Txtt401_88.Text.Trim();
			_t401.t401_54 = Txtt401_54.Text.Trim();
			_t401.t401_55 = Txtt401_55.Text.Trim();
			_t401.t401_89 = Txtt401_89.Text.Trim();
			_t401.t401_90 = Txtt401_90.Text.Trim();
			_t401.t401_56 = Txtt401_56.Text.Trim();
			_t401.t401_57 = Txtt401_57.Text.Trim();
			_t401.collection_time = Txtcollection_time.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_t401(_t401);
            else
                isok = mgr.Add_t401(_t401);
            if (isok)
            {
                t401_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("t401中执行了保存（插入或修改），并成功");
                t401_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}